package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.CheckInApplyDto;
import com.zzyl.service.CheckInService;
import com.zzyl.vo.CheckInDetailVo;
import com.zzyl.vo.CheckInPageQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理端 - 入住管理
 *
 * @author itcast
 */
@RestController
@RequestMapping("/check-in")
@Api(tags = "管理端 - 入住管理")
public class CheckInController {

    @Autowired
    private CheckInService checkInService;

    @PostMapping("/apply")
    @ApiOperation(value = "申请入住")
    public ResponseResult<Void> apply(@RequestBody CheckInApplyDto checkInApplyDto) {
        checkInService.apply(checkInApplyDto);
        return ResponseResult.success();
    }

    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页查询入住列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "elderName", value = "老人姓名，模糊查询", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "idCardNo", value = "身份证号，精确查询", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNum", value = "页码", example = "1", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", example = "10", required = true, dataTypeClass = Integer.class)
    })
    public ResponseResult<PageResponse<CheckInPageQueryVo>> pageQuery(@RequestParam(value = "elderName", required = false) String elderName,
                                                                      @RequestParam(value = "idCardNo", required = false) String idCardNo,
                                                                      @RequestParam("pageNum") Integer pageNum,
                                                                      @RequestParam("pageSize") Integer pageSize) {
        return ResponseResult.success(checkInService.pageQuery(elderName, idCardNo, pageNum, pageSize));
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查询入住详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "入住id", required = true, dataTypeClass = Long.class)
    })
    public ResponseResult<CheckInDetailVo> detail(@PathVariable("id") Long id) {
        return ResponseResult.success(checkInService.detail(id));
    }
}

